﻿@model LogOnViewModel
@{
    ViewBag.Title = "Sign In";
    ViewBag.Tab = "Sign in";
    ViewBag.SmPageColumns = GalleryConstants.ColumnsWideAuthenticationSm;
    ViewBag.MdPageColumns = GalleryConstants.ColumnsWideAuthenticationMd;
}

<section role="main" class="container main-container page-sign-in">
    @if (Model.External.FoundExistingUser)
    {
        <div class="row">
            <div class="col-xs-12">
                <h1 class="text-center">Link @Model.External.ProviderAccountNoun</h1>
            </div>
        </div>
        <div class="row">
            <div class="@ViewHelpers.GetColumnClasses(ViewBag)">
                @if (Model.External.ExistingUserCanBeLinked)
                {
                    <p class="text-center">
                        We found an account with this email address. Sign in with your NuGet.org password to link with this Microsoft account.
                    </p>
                    <p class="text-center">
                        Note that <b>your existing password login will be disabled</b> and you will need to use this Microsoft account to sign into NuGet.org
                    </p>
                    <p class="text-center">
                        Please <a href="mailto:@Config.Current.GalleryOwner.Address">contact support</a> if you need more assistance.
                    </p>

                    @Html.Partial("_SignIn", Model)
                }
                else
                {
                    switch (Model.External.ExistingUserLinkingError)
                    {
                        case AssociateExternalAccountViewModel.ExistingUserLinkingErrorType.AccountIsAlreadyLinked:
                            <p class="text-center">
                                The account with the email @Model.SignIn.UserNameOrEmail is linked to another Microsoft account.
                            </p>
                            <p class="text-center">
                                Please refer to the  @(ViewHelpers.GetExternalUrlAnchorTag("FAQs page", GalleryConstants.FAQLinks.EmailLinkedToAnotherMSAAccount))
                                for steps to resolve this issue.
                            </p>
                            break;
                        case AssociateExternalAccountViewModel.ExistingUserLinkingErrorType.AccountIsOrganization:
                            <p class="text-center">
                                The email @Model.SignIn.UserNameOrEmail is linked to an organization.
                            </p>
                            <p class="text-center">
                                If you would like to manage the organization account, you must sign in as one of its admins.
                            </p>

                            <p class="text-center">
                                Please <a href="mailto:@Config.Current.GalleryOwner.Address">contact support</a> if you need more assistance.
                            </p>
                            break;
                        default:
                            <p class="text-center">
                                An unknown error occurred.
                            </p>

                            <p class="text-center">
                                Please <a href="mailto:@Config.Current.GalleryOwner.Address">contact support</a> if you need more assistance.
                            </p>
                            break;
                    }
                }
            </div>
        </div>
    }
    else
    {
        <div class="row">
            <div class="col-xs-12">
                <h1 class="text-center">Register @Model.External.ProviderAccountNoun</h1>
            </div>
        </div>
        <div class="row">
            <div class="@ViewHelpers.GetColumnClasses(ViewBag)">
                <p class="text-center">
                    Looks like we don't have an account with this email address (@Model.Register.EmailAddress) in our records.
                </p>
                <p class="text-center">
                    Please provide a username so that we can create an account for you!
                </p>

                @Html.Partial("_Register", Model)
            </div>
        </div>
    }
</section>